#!/bin/bash
# 构建并部署脚本
# 用法: ./build.sh

echo "=========================================="
echo "若依系统 - 构建部署脚本"
echo "=========================================="

# 进入项目目录
cd "$(dirname "$0")"

# 1. 编译打包
echo ""
echo "[1/3] 开始编译打包..."
mvn clean package -DskipTests

if [ $? -ne 0 ]; then
    echo "❌ 编译失败！"
    exit 1
fi

echo "✅ 编译成功"

# 2. 备份旧jar文件
echo ""
echo "[2/3] 备份并替换jar文件..."
if [ -f "ruoyi-admin.jar" ]; then
    mv ruoyi-admin.jar ruoyi-admin.jar.backup
    echo "已备份旧jar文件: ruoyi-admin.jar.backup"
fi

cp ruoyi-admin/target/ruoyi-admin.jar ruoyi-admin.jar
echo "✅ jar文件已更新"

# 3. 重启服务
echo ""
echo "[3/3] 重启服务..."
bash ry.sh restart

echo ""
echo "=========================================="
echo "✅ 构建部署完成！"
echo "=========================================="
echo ""
echo "日志文件: logs/ruoyi-admin.jar.log"
echo "查看日志: tail -f logs/ruoyi-admin.jar.log"
echo "服务状态: bash ry.sh status"
echo ""

